package com.atguigu.ssyx.home.service.impl;

import com.atguigu.ssyx.client.prouduct.ProductFeignClient;
import com.atguigu.ssyx.client.search.SkuFeignClient;
import com.atguigu.ssyx.client.user.UserFeigntCilent;
import com.atguigu.ssyx.home.service.HomeService;
import com.atguigu.ssyx.model.product.Category;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.model.search.SkuEs;
import com.atguigu.ssyx.model.user.User;
import com.atguigu.ssyx.vo.user.LeaderAddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HomeServiceImpl implements HomeService {

    @Autowired
    private UserFeigntCilent userFeigntCilent;

    @Autowired
    private ProductFeignClient productFeignClient;

    @Autowired
    private SkuFeignClient skuFeignClient;

    //    首页数据显示接口
    @Override
    public Map<String, Object> homeData(Long userId) {
        Map<String, Object> map = new HashMap<>();
//        1.根据userId获得当前登录用户的提货点。 userId来自于线程
//        远程调用service-user模块接口获得需要的数据。
        LeaderAddressVo leaderAddressVo = userFeigntCilent.getUserAddresByUserId(userId);

        map.put("leaderAddressVo", leaderAddressVo);
//      2.获得所有分类接口
//        远程调用获得所service-project模块接口有
        List<Category> allCategoryList = productFeignClient.findAllCategoryList();
        map.put("allCategoryList", allCategoryList);


//        3.获得新人专项商品。
//        远程调用servicce-project模块
        List<SkuInfo> newPersonSkuInfoList = productFeignClient.findNewPersonSkuInfoList();
        map.put("newPersonSkuInfoList", newPersonSkuInfoList);

//        4.获得爆款商品。
        List<SkuEs> hotSkuList = skuFeignClient.findHotSkuList();
        map.put("hotSkuList", hotSkuList);

//        5.封装map.
        return map;
    }
}
